import request from '@/utils/request';

const addressApi = {
  /**
   * 获取地址列表
   */
  getAddressList() {
    return request({
      url: '/api/address/list',
      method: 'GET'
    });
  },

  /**
   * 获取地址详情
   * @param {string} id - 地址ID
   */
  getAddressDetail(id) {
    return request({
      url: `/api/address/detail/${id}`,
      method: 'GET'
    }).then(res => {
      // 为了演示，这里可以使用模拟数据
      return Promise.resolve({
        id: id,
        name: '张三',
        phone: '13800138000',
        province: '广东省',
        city: '深圳市',
        district: '南山区',
        detail: '科技园南路88号',
        isDefault: true
      });
    });
  },

  /**
   * 添加新地址
   * @param {Object} address - 地址信息
   */
  addAddress(address) {
    return request({
      url: '/api/address/add',
      method: 'POST',
      data: address
    });
  },

  /**
   * 更新地址
   * @param {Object} address - 地址信息
   */
  updateAddress(address) {
    return request({
      url: `/api/address/update/${address.id}`,
      method: 'PUT',
      data: address
    });
  },

  /**
   * 删除地址
   * @param {string} id - 地址ID
   */
  deleteAddress(id) {
    return request({
      url: `/api/address/delete/${id}`,
      method: 'DELETE'
    });
  },

  /**
   * 设置默认地址
   * @param {string} id - 地址ID
   */
  setDefaultAddress(id) {
    return request({
      url: `/api/address/setDefault/${id}`,
      method: 'PUT'
    });
  }
};

export default addressApi; 